﻿<style>
    .el-tabs--border-card > .el-tabs__content {
        padding: 5px;
    }

    .el-tabs__item {
        height: 30px;
        line-height: 30px;
    }

    .el-tabs__nav-next, .el-tabs__nav-prev {
        line-height: 30px;
    }

    .el-tabs__nav-wrap.is-scrollable.is-top {
        width: 100%;
    }

    .el-dialog__body {
        padding: 10px 20px;
    }
</style>
<style scoped>
    .el-radio {
        color: #606266;
        cursor: pointer;
        margin-right: 10px;
    }
</style>
<template>

    <div v-loading="isLoading">

        <el-dialog title="关联信息" :visible.sync="cellLinkDataDlgVisible" :close-on-click-modal="false">
            <el-form :model="cellDataOption">
                <el-form-item label="标签页名称" :label-width="formLabelWidth">
                    <el-input v-model="cellDataOption.sheetName" disabled autocomplete="off"></el-input>
                </el-form-item>

                <el-form-item label="单元格所在行" :label-width="formLabelWidth">
                    <el-input disabled v-model="cellDataOption.rowIndex"></el-input>
                </el-form-item>
                <el-form-item label="单元格所在列" :label-width="formLabelWidth">
                    <el-input disabled v-model="cellDataOption.colIndex"></el-input>
                </el-form-item>
                <el-form-item label="单元格类型" :label-width="formLabelWidth">
                    <el-radio-group v-model="cellDataOption.dataType" size="medium">
                        <el-radio-button label="compute">计算数据</el-radio-button>
                        <el-radio-button label="year">年份</el-radio-button>
                        <el-radio-button label="oilPrice">油价分组</el-radio-button>
                    </el-radio-group>
                </el-form-item>
                <template v-if="cellDataOption.dataType == 'year'">
                    <!--                                 <el-form-item label="排序方式" :label-width="formLabelWidth">-->
                    <!--                                     <el-radio-group v-model="cellDataOption.order" size="medium">-->
                    <!--                                           <el-radio-button label="asc" >升序</el-radio-button>-->
                    <!--                                           <el-radio-button label="desc">降序</el-radio-button>-->
                    <!--                                       </el-radio-group>-->
                    <!--                                 </el-form-item>-->
                    <!--                                 <el-form-item label="合计位置" :label-width="formLabelWidth">-->
                    <!--                                     <el-radio-group v-model="cellDataOption.sumPosition" size="medium">-->
                    <!--                                           <el-radio-button label="none" >不展示</el-radio-button>-->
                    <!--                                           <el-radio-button label="begin">开头</el-radio-button>-->
                    <!--                                           <el-radio-button label="end">结尾</el-radio-button>-->
                    <!--                                       </el-radio-group>-->
                    <!--                                 </el-form-item>-->
                </template>
                <template v-else-if="cellDataOption.dataType == 'compute'||cellDataOption.dataType == 'oilPrice'">
                    <el-form-item label="相同数据合并" :label-width="formLabelWidth">
                        <el-radio-group v-model="cellDataOption.mergeSame" size="medium">
                            <el-radio-button :label="false">不合并</el-radio-button>
                            <el-radio-button :label="true">合并</el-radio-button>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="保留小数位" :label-width="formLabelWidth">
                        <el-input v-model="cellDataOption.digit" type="number"></el-input>
                    </el-form-item>
                    <el-form-item label="计算单元"
                                  :label-width="formLabelWidth">
                        <el-cascader
                                :props="{emitPath: false}"
                                :show-all-levels="true"
                                :options="computeUnitList"
                                v-model="cellDataOption.data"
                                clearable
                                filterable></el-cascader>
                    </el-form-item>
                    <el-form-item
                            v-if="computeUnitMap[cellDataOption.data]&&computeUnitMap[cellDataOption.data].type!='compute'"
                            label="合计类型" :label-width="formLabelWidth">
                        <el-cascader
                                :props="{emitPath: false}"
                                :show-all-levels="true"
                                :options="sumTypeList"
                                v-model="cellDataOption.sumType"
                                clearable
                                filterable></el-cascader>

                        <!--              <el-select filterable v-model="cellDataOption.sumType" placeholder="请选择">-->
                        <!--                <el-option-->
                        <!--                  v-for="item in sumTypeList"-->
                        <!--                  :key="item.id"-->
                        <!--                  :label="item.name"-->
                        <!--                  :value="item.id">-->
                        <!--                </el-option>-->
                        <!--              </el-select>-->
                    </el-form-item>
                    <el-form-item
                            v-else-if="computeUnitMap[cellDataOption.data]&&computeUnitMap[cellDataOption.data].type=='compute'"
                            label="" :label-width="formLabelWidth">
                        <el-alert style="line-height:normal"
                                  title="非扩展数据"
                                  description="该计算单元为汇总计算结果数据，不会自动扩展"
                                  type="success"
                                  :closable="false">
                        </el-alert>
                    </el-form-item>
                </template>
                <template v-else-if="cellDataOption.dataType == 'sensAnalysis'">
                    <el-form-item label="分析指标"
                                  :label-width="formLabelWidth">
                        <el-cascader
                                :props="{emitPath: false}"
                                :show-all-levels="true"
                                :options="riskAnalysisItemList"
                                v-model="cellDataOption.data"
                                clearable
                                filterable>
                            <template slot-scope="{node,data}">
                                <span style="float: left">{{ data.label }}</span>
                                <span v-if="node.isLeaf&&data.tip"
                                      style="padding-left:20px;float: right; color: #8492a6; font-size: 13px">{{ data.tip }}</span>
                            </template>
                        </el-cascader>
                    </el-form-item>
                    <el-form-item v-if="cellDataOption.data&&cellDataOption.data!='rate'" label="保留小数位"
                                  :label-width="formLabelWidth">
                        <el-input v-model="cellDataOption.digit" type="number"></el-input>
                    </el-form-item>
                </template>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cellLinkDataDlgVisible = false">取 消</el-button>
                <el-button type="primary" @click="updateCellOptionData">保 存</el-button>
            </div>
        </el-dialog>

        <el-dialog title="导出配置" :visible.sync="globalSettingDlgVisible" :close-on-click-modal="false">
            <el-form :model="templateInfo.dataConfig">
                <el-form-item label="合计位置" :label-width="formLabelWidth">
                    <el-radio-group v-model="templateInfo.dataConfig.sumPosition" size="medium">
                        <el-radio-button label="none">不展示</el-radio-button>
                        <el-radio-button label="begin">开头</el-radio-button>
                        <el-radio-button label="end">结尾</el-radio-button>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="globalSettingDlgVisible = false">取 消</el-button>
                <el-button type="primary" @click="updateExportSetting">保 存</el-button>
            </div>
        </el-dialog>

        <el-dialog title="全局配置" :visible.sync="sheetSettingDlgVisible" :close-on-click-modal="false"
                   @close="sheetSettingDlgClose">
            <el-table id="sheetConfigList" :data="templateInfo.excelPreviewData.sheetList" border highlight-current-row
                      empty-text="暂无数据"
                      v-loading="isLoading" :key="modelInfo.id+'_sheetlist'"
                      :header-cell-style="{background:'#f5f7fa'}">
                <el-table-column type="index" label="序号" show-overflow-tooltip width="50" align="center">
                </el-table-column>
                <el-table-column label="标签页名称" header-align="center" width="200" show-overflow-tooltip>
                    <template slot-scope="scope">
                        {{scope.row.name}}
                    </template>
                </el-table-column>
                <el-table-column label="展示图标" align="center">
                    <template slot-scope="scope">
                        <el-popover
                                v-if="sheetConfigMap[scope.row.name]"
                                placement="right"
                                width="400"
                                v-model="sheetConfigMap[scope.row.name].showSheetIcon"
                                trigger="manual">
                            <el-col span="4" v-for="icon in iconList"
                                    style="font-size:18px!important;text-align:center;padding: 10px;height: auto;line-height: normal;"
                                    :class="sheetConfigMap[scope.row.name].icon==icon?'el-menu-item is-active':'el-menu-item'"
                                    @click.native="sheetConfigMap[scope.row.name].icon=icon,sheetConfigMap[scope.row.name].showSheetIcon=false">
                                <i :class="icon"></i>
                            </el-col>
                            <i v-if="sheetConfigMap[scope.row.name].icon"
                               :class="sheetConfigMap[scope.row.name].icon" slot="reference"
                               @click="showSelectIconPanel(scope.row.name)"></i>
                            <i v-else slot="reference" @click="showSelectIconPanel(scope.row)">无</i>
                        </el-popover>
                    </template>
                </el-table-column>
<!--                <el-table-column label="显示评价开始前一年" width="200" align="center">-->
<!--                    <template slot-scope="scope">-->
<!--                        <el-switch v-model="sheetConfigMap[scope.row].showLastYear"></el-switch>-->
<!--                    </template>-->
<!--                </el-table-column>-->
                <el-table-column label="油价扩展方向" align="center" width="150">
                    <template slot-scope="scope">
                        <el-radio-group v-model="sheetConfigMap[scope.row.name].groupExpandDirection">
                            <el-radio label="vertical">向下</el-radio>
                            <el-radio label="horizontal">向右</el-radio>
                        </el-radio-group>
                    </template>
                </el-table-column>
<!--                <el-table-column label="数据扩展方向" align="center" width="150">-->
<!--                    <template slot-scope="scope">-->
<!--                        <el-radio-group v-model="sheetConfigMap[scope.row].expandDirection">-->
<!--                            <el-radio label="vertical">向下</el-radio>-->
<!--                            <el-radio label="horizontal">向右</el-radio>-->
<!--                        </el-radio-group>-->
<!--                    </template>-->
<!--                </el-table-column>-->
            </el-table>
            <el-form style="margin-top: 20px;">
                <el-form-item label="合计位置选择"
                              :label-width="formLabelWidth">
                    <el-radio-group v-model="templateInfo.dataConfig.sumPosition" size="small">
                        <el-radio-button label="none">不展示</el-radio-button>
                        <el-radio-button label="begin">开头</el-radio-button>
                        <el-radio-button label="end">结尾</el-radio-button>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="数据扩展方向"
                              :label-width="formLabelWidth">
                    <el-select filterable v-model="templateInfo.dataConfig.expandDirection" placeholder="请选择">
                        <el-option
                                label="横向扩展(向右)"
                                value="horizontal">
                        </el-option>
                        <el-option
                                label="纵向扩展(向下)"
                                value="vertical">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="sheetSettingDlgVisible = false,showSheetIcon=false">取 消</el-button>
                <el-button type="primary" @click="updateSheetSetting">保 存</el-button>
            </div>
        </el-dialog>

        <el-row v-if="templateInfo.excelPreviewData.sheetList&&templateInfo.excelPreviewData.sheetList.length>0">
            <div style="padding: 10px;float: right;margin-top: -50px;">
                <!--          <el-button type="primary" size="small" icon="el-icon-setting" @click="globalSettingDlgVisible=true">全局配置-->
                <!--          </el-button>-->
                <el-button type="primary" size="small" icon="el-icon-setting"
                           @click="openSheetSettingDlg">全局配置
                </el-button>
                <el-button type="primary" size="small" icon="el-icon-download" @click="downloadTemplateFile">模板下载
                </el-button>
                <el-upload
                        style="float: right;margin-left: 15px;"
                        ref="upload"
                        action="/export/template/upload"
                        :show-file-list="false"
                        :data="{modelId:modelInfo.id,type:'multi_oil'}"
                        :before-upload="beforeUpload"
                        :on-success="uploadSuccess"
                        :on-error="uploadFailed"
                        accept=".xlsx,.xls">
                    <el-button icon="el-icon-download" size="small" type="primary">模板上传</el-button>
                </el-upload>

            </div>
            <el-col span="24">
                <!--        <div style="height: 50px;"></div>-->
                <excel-view v-if="templateInfo.excelPreviewData" :data="templateInfo.excelPreviewData" @cell-click="cellClick"
                            :min-text-length="4"
                            :max-height="pageHeight-10"
                            :cell-style="templateDataConfigStateStyle" :formatText="cellFormatter"></excel-view>
            </el-col>
        </el-row>
        <el-upload v-else-if="isLoading==false"
                   style="margin-top: 20px"
                   ref="upload"
                   action="/export/template/upload"
                   :show-file-list="false"
                   :data="{modelId:modelInfo.id,type:'multi_oil'}"
                   :on-success="uploadSuccess"
                   :before-upload="beforeUpload"
                   :on-error="uploadFailed"
                   accept=".xlsx,.xls"
                   drag>
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            <div slot="tip" class="el-upload__tip">数据单元格请使用$进行占位，以便进行后续数据关联操作</div>
        </el-upload>
    </div>


</template>

<script>
    export default {
        name: "OilPriceModule",
        $$route: {
            path: 'oil-price-module',
            parentName: 'ModelInfo',
        },
        props:{
            modelInfo:{},
            pageHeight:{}
        },
        data() {
            return {
                isLoading: true,
                formLabelWidth: '120px',
                computeTreeData: [],
                templateInfo:{dataConfig:{},excelPreviewData:{}},
                sheetConfigMap: {},
                cellDataOption: {},
                cellLinkDataDlgVisible: false,
                globalSettingDlgVisible: false,
                sheetSettingDlgVisible: false,
                sumTypeList: [],
                computeUnitList: [],
                computeUnitList2: [],
                computeUnitMap: [],
                riskAnalysisItemList: [],
                showSheetIcon: false,
            }
        },
        computed: {},
        created: function () {

        },
        mounted() {
            // const modelId = this.$route.params.id;
            const modelId = this.modelInfo.id;
            // this.loadModelInfo(modelId, () => {
            this.modelEditable = this.modelInfo.state != 'publish';
            this.loadExportTemplateDataConfig((response)=>{
                // this.loadExportTemplate(modelId);
            })

            // });
            this.loadComputeUnitList(modelId, this.loadSumType);
        },
        methods: {
            openSheetSettingDlg: function () {
                var data = {};
                var templateDataConfig = this.templateInfo.dataConfig;
                if (this.templateInfo.excelPreviewData.sheetList && this.templateInfo.excelPreviewData.sheetList.length > 0) {
                    for (var sheetInfo of this.templateInfo.excelPreviewData.sheetList) {
                        var name = sheetInfo.name;
                        var item = {};
                        item.modelId = this.modelInfo.id;
                        item.name = name;
                        item.showSheetIcon = false;
                        item.icon = '';

                        if (templateDataConfig.sheetConfigMap && templateDataConfig.sheetConfigMap[name]) {
                            item.icon = templateDataConfig.sheetConfigMap[name].icon;
                            item.showLastYear = templateDataConfig.sheetConfigMap[name].showLastYear;
                            item.groupExpandDirection = templateDataConfig.sheetConfigMap[name].groupExpandDirection;
                            item.expandDirection = templateDataConfig.sheetConfigMap[name].expandDirection;
                        }
                        data[name] = item;
                    }
                    this.sheetConfigMap = data;
                }
                this.sheetSettingDlgVisible = true;
            },
            sheetSettingDlgClose: function () {
                for (var sheet in this.sheetConfigMap) {
                    this.sheetConfigMap[sheet].showSheetIcon = false;
                }
            },
            showSelectIconPanel: function (sheet) {
                var data = {};
                for (var key in this.sheetConfigMap) {
                    data[key] = this.sheetConfigMap[key];
                    if (key == sheet) {
                        data[key].showSheetIcon = !this.sheetConfigMap[key].showSheetIcon;
                    } else {
                        data[key].showSheetIcon = false;
                    }
                }
                this.sheetConfigMap = data;
            },

            loadComputeUnitTree: function (id) {
                // this.isLoading = true;
                this.$get("/compute/tree?modelId=" + id, {}, (response) => {
                    this.computeTreeData = response.data;
                });
            },
            loadComputeUnitList: function (id, hook) {
                // this.isLoading = true;
                this.$get("/compute/data?type=summary&modelId=" + id, {}, (response) => {

                    var dataMap = {};
                    var dataMap2 = {};
                    for (var i = 0; i < response.data.length; i++) {
                        var item = response.data[i];
                        this.computeUnitMap[item.ref] = item;
                        var list = dataMap[item.tag];
                        if (!list) {
                            list = [];
                            dataMap[item.tag] = list;
                        }
                        list.push(item);
                        if (item.type == 'compute') {
                            var list2 = dataMap2[item.tag];
                            if (!list2) {
                                list2 = [];
                                dataMap2[item.tag] = list2;
                            }
                            list2.push(item);
                        }
                    }
                    var resultList = [];
                    for (var key in dataMap) {
                        var list = dataMap[key];
                        var item = {label: key, value: key, children: []};
                        for (var i = 0; i < list.length; i++) {
                            item.children.push({label: list[i].name, value: list[i].ref, type: list[i].type});
                        }
                        resultList.push(item);
                    }
                    this.computeUnitList = resultList;

                    var resultList2 = [];
                    for (var key in dataMap2) {
                        var list = dataMap2[key];
                        var item = {label: key, value: key, children: []};
                        for (var i = 0; i < list.length; i++) {
                            item.children.push({label: list[i].name, value: list[i].ref, type: list[i].type});
                        }
                        resultList2.push(item);
                    }
                    this.computeUnitList2 = resultList2;
                    if (hook) {
                        hook();
                    }
                    this.loadSensAnalysisItemList(id, response.data);
                });

            },
            loadSensAnalysisItemList: function (id, unitDataList) {
                this.$get("/riskAnalysis/config/data?modelId=" + id, {}, (response) => {
                  if(!response.data) {
                    return;
                  }
                    if (!response.data.computeUnitRefList) {
                        return;
                    }
                    var balanceAnalysis = false;
                    if (response.data.balanceAnalysis) {
                        balanceAnalysis = true;
                    }
                    var map = {};
                    for (var ref of response.data.computeUnitRefList) {
                        map[ref] = true;
                    }
                    var unitList = unitDataList.filter(data => {
                        return map[data.ref] == true;
                    });
                    this.$get("/riskAnalysis/item/data?modelId=" + id, {}, (response) => {

                        var resultList = [{label: '敏感性分析变化率', value: 'rate', tip: '扩展数据'}];
                        // resultList.push({label:''})
                        for (var item of response.data) {
                            var option = {label: item.name, value: '', children: []};
                            var sensItem = {label: '敏感性分析数据', value: item.id + ':' + 'sensanalysis'};
                            if (unitList.length == 1) {
                                sensItem.value = sensItem.value + ":" + unitList[0].ref;
                                sensItem.tip = '扩展数据';
                            } else if (unitList.length > 1) {
                                sensItem.children = [];
                                for (var unit of unitList) {
                                    // sensItem.children.push({
                                    //     label: unit.tag + ':' + unit.name,
                                    //     value: item.id + ":" + unit.ref
                                    // });
                                    sensItem.children.push({
                                        label: unit.tag + ':' + unit.name,
                                        value: sensItem.value + ":" + unit.ref,
                                        tip: '扩展数据'
                                    });
                                }
                            }
                            option.children.push(sensItem);
                            option.children.push({
                                disabled: !balanceAnalysis,
                                label: '评价值',
                                value: item.id + ':' + 'value'
                            })
                            option.children.push({
                                disabled: !balanceAnalysis,
                                label: '基准变化率',
                                value: item.id + ':' + 'reference_rate'
                            })
                            option.children.push({
                                disabled: !balanceAnalysis,
                                label: '基准平衡点',
                                value: item.id + ':' + 'reference_result'
                            })
                            option.children.push({
                                disabled: !balanceAnalysis,
                                label: '盈亏变化率',
                                value: item.id + ':' + 'bep_rate'
                            })
                            option.children.push({
                                disabled: !balanceAnalysis,
                                label: '盈亏平衡点',
                                value: item.id + ':' + 'bep_result'
                            })

                            resultList.push(option);
                        }
                        this.riskAnalysisItemList = resultList;
                    });
                })
                // this.isLoading = true;

            },
            loadSumType: function () {
                this.$get("/meta/type/sum-type", {}, (response) => {
                    var resultList = [];
                    for (var item of response.data) {
                        resultList.push({label: item.name, value: item.id});
                    }
                    var unitSumList = [];
                    for (var unitItem of this.computeUnitList) {
                        if (!unitItem.children) {
                            continue;
                        }
                        var unitList = [];
                        for (var unit of unitItem.children) {
                            if (unit.type == 'compute') {
                                unitList.push(unit);
                            }
                        }
                        if (unitList.length > 0) {
                            unitSumList.push({label: unitItem.label, value: unitItem.value, children: unitList});
                        }
                    }
                    if (unitSumList.length > 0) {
                        resultList.push({label: '模型选择', value: 'compute', children: unitSumList})
                    }
                    this.sumTypeList = resultList;
                });
            },

            updateCellOptionData: function () {
                // cellLinkDataDlgVisible
                this.$post("/export/config/cell/update", this.cellDataOption, (response) => {

                    this.$message({
                        message: '更新成功',
                        type: 'success'
                    });
                    this.loadExportTemplateDataConfig();
                    this.cellLinkDataDlgVisible = false;
                });
            },
            openCellDataConfigDlg: function (sheet, data) {
                // var key = data.row.sheetName+"_"+data.row.rowIndex+"_" + data.column.property;
                var key = data.row.rowIndex + "_" + data.column.property;
                var option = null;
                var sheetConfig = this.dataConfig.sheetConfigMap[sheet];
                if (sheetConfig && sheetConfig.cellDataConfigMap) {
                    option = sheetConfig.cellDataConfigMap[key];
                }
                // var option = this.dataConfig.option = this.dataConfig.cellDataConfigMap[key];[key];
                if (option)
                    this.cellDataOption = {
                        colIndex: option.colIndex
                        , dataType: option.dataType
                        , order: option.order
                        , rowIndex: option.rowIndex
                        , sheetName: option.sheetName
                        , modelId: this.modelInfo.id
                        , templateId: this.templateInfo.id
                        , data: option.data
                        , sumType: option.sumType
                        // ,sumPosition:option.sumPosition
                        , digit: option.digit
                        , mergeSame: option.mergeSame
                    };
                this.cellLinkDataDlgVisible = true;
            },

            uploadSuccess: function (data) {
                if (data.code != 0) {
                    this.$message({
                        message: data.msg,
                        type: 'warning'
                    });
                    return;
                }
                this.$message({
                    message: '上传成功',
                    type: 'success'
                });
                this.loadExportTemplateDataConfig();
            },
            uploadFailed: function () {
                this.$message.error('上传失败');
            },


            loadExportTemplateDataConfig: function (hook) {
                this.isLoading = true;
                this.$get("/export/template/info", {modelId:this.modelInfo.id,type:'multi_oil'}, (response) => {

                  if(!response.data||!response.data.dataConfig) {
                    return;
                  }
                    this.templateInfo = response.data;
                  var config = this.templateInfo.dataConfig;
                  if(config&&config.sheetConfigList) {
                    var sheetConfigMap = {};
                    for(var item of config.sheetConfigList) {
                      sheetConfigMap[item.name] = item;
                      var cellDataConfigMap = {};
                      if(item.cellConfigList) {
                        for(var cellConfig of item.cellConfigList) {
                          cellDataConfigMap[cellConfig.rowIndex+'_'+cellConfig.colIndex] = cellConfig;
                        }
                        item.cellDataConfigMap = cellDataConfigMap;
                      }
                    }
                    config.sheetConfigMap = sheetConfigMap;
                  }
                    if (!this.templateInfo.dataConfig.expandDirection) {
                        this.templateInfo.dataConfig.expandDirection = 'horizontal'
                    }
                    if (hook) {
                        hook();
                    }
                }, () => {
                    this.isLoading = false;
                });
            },

            updateExportSetting: function (showTip) {
                this.templateInfo.dataConfig.modelId = this.modelInfo.id;
                this.$post("/export/config/global/update", this.templateInfo.dataConfig, (response) => {
                    if (showTip != false) {
                        this.$message({
                            message: '更新成功',
                            type: 'success'
                        });
                    }
                    this.globalSettingDlgVisible = false;
                });
            },
            updateSheetSetting: function () {
                // this.sheetConfig.modelId = this.modelInfo.id;
                this.$post("/export/config/sheet/update?templateId=" + this.templateInfo.id, this.sheetConfigMap, (response) => {
                    this.$message({
                        message: '更新成功',
                        type: 'success'
                    });
                    this.loadExportTemplateDataConfig();
                    this.updateExportSetting(false);
                    this.sheetSettingDlgVisible = false;
                });
            },
            downloadTemplateFile: function () {
                window.open(this.$ctx+"/export/template/download?id=" + this.templateInfo.id);
            },
            templateDataConfigStateStyle: function ({row, column, rowIndex, columnIndex}, sheet) {
                if (row[column.property] != "$") {
                    return;
                }
                var sheetName = sheet.name;
                var key = row.rowNum + 1 + "_" + (parseInt(column.property.replace('col', '')) + 1);
                var completeStyle = {'background-color': '#f0f9eb','color': '#409EFF',cursor:'pointer','text-align':'center'};
                var config = this.templateInfo.dataConfig;
                if (config.sheetConfigMap
                    && config.sheetConfigMap[sheetName]
                    && config.sheetConfigMap[sheetName].cellDataConfigMap[key]
                    && config.sheetConfigMap[sheetName].cellDataConfigMap[key].dataType == 'year') {
                    return completeStyle;
                } else if (config.sheetConfigMap
                    && config.sheetConfigMap[sheetName]
                    && config.sheetConfigMap[sheetName].cellDataConfigMap[key]
                    && config.sheetConfigMap[sheetName].cellDataConfigMap[key].data) {
                    return completeStyle;
                } else {
                    return {'background-color': '#fdf6ec','color': '#409EFF',cursor:'pointer','text-align':'center'}
                }


            },
            cellFormatter: function ({row, column, cellValue, index},sheet) {

                if (row[column.property] != "$") {
                    return row[column.property];
                }
                var sheetName = sheet.name;
                var key = row.rowNum + 1 + "_" + (parseInt(column.property.replace('col', '')) + 1);
                var config = this.templateInfo.dataConfig;

                // if(this.templateInfo.publish||!this.checkPermission('template:update')) {
                //     return '查看数据';
                // }
                if(this.modelInfo.state!=0) {
                    return '查看数据';
                }
                if (config.sheetConfigMap
                    && config.sheetConfigMap[sheetName]
                    && config.sheetConfigMap[sheetName].cellDataConfigMap[key].dataType == 'year') {
                    return '编辑数据';
                } else if (config.sheetConfigMap
                    && config.sheetConfigMap[sheetName]
                    && config.sheetConfigMap[sheetName].cellDataConfigMap[key].data) {
                    return '编辑数据';
                } else {
                    return '关联数据';
                }


            },
            cellClick: function (row, column, cell, event, sheet) {
                if (row[column.property] != '$') {
                    return;
                }
                var key = row.rowNum + 1 + "_" + (parseInt(column.property.replace('col', '')) + 1);
                var option = null;
                var sheetConfig = this.templateInfo.dataConfig.sheetConfigMap[sheet.name];
                if (sheetConfig && sheetConfig.cellDataConfigMap) {
                    option = sheetConfig.cellDataConfigMap[key];
                }
                if (option)
                    this.cellDataOption = {
                        id:option.id,
                        colIndex: option.colIndex
                        , dataType: option.dataType
                        , order: option.order
                        , rowIndex: option.rowIndex
                        , sheetName: option.sheetName
                        , templateId: this.templateInfo.id
                        , data: option.data
                        , sumType: option.sumType
                        // ,sumPosition:option.sumPosition
                        , digit: option.digit
                        , mergeSame: option.mergeSame
                    };
                this.cellLinkDataDlgVisible = true;
            },
          beforeUpload(){
            this.isLoading = true;
            return true;
          },

        },

    }
</script>
